package handler

import (
	"context"
	"fmt"
	"user_srv/internal/service"
	pb "user_srv/proto"
)

type UserServer struct {
	pb.UnimplementedUserServer
}

func (u *UserServer) Login(ctx context.Context, req *pb.LoginRequest) (resp *pb.LoginResponse, err error) {

	mobile, err := service.FindUserByMobile(req.Mobile)
	if err != nil {
		return nil, fmt.Errorf("查询失败")
	}
	if mobile.ID == 0 {
		return nil, fmt.Errorf("用户不存在")
	}
	if mobile.Password != req.Password {

		return nil, fmt.Errorf("密码错误")
	}
	return &pb.LoginResponse{Id: int32(mobile.ID)}, nil
}
